package org.example.myleet.p1716;

public class Solution {
    public int totalMoney(int n) {
        //有多少个星期
        int period = n / 7;
        //最后一个星期还剩多少天
        int remainder = n % 7;
        //每个星期从1到7共28，多少个完整星期就存多少个28
        int result = 28 * period;
        //每个完整的星期还会额外存入7 * (period - 1)元，是个等差数列，求和
        result += 7 * (period - 1) * period / 2;
        //剩余不满一周的几天也会存入1～remainder元
        for (int i = 1; i <= remainder; ++i) {
            result += i;
        }
        //并且剩余不满一周的几天每天也会额外存入period
        result += remainder * period;
        return result;
    }
}
